package org.lab.tracecash.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Table;

import org.lab.tracecash.model.Account;

/**
 * Representa una regla definida por el usuario para establecer de forma automatica los {@link Account} de entrada o salida de una {@link org.lab.tracecash.model.Transaction}.
 * <p>
 * Este puede ser el caso por ejemplo de importar una hoja de calculo con los movimientos de una cuenta y asignar a cada movimiento un tipo de gasto a partir de la descripcion del
 * </p>
 */
@Entity
@Table(name = "tc_transaction_rule")
public class TransactionResolverRule {

	@Id
	@GeneratedValue
	@Column(name = "id")
	private Long id;

	@Column(name = "name", length = 256, nullable = true)
	private String name;

	@Column(name = "eval_source", nullable = false)
	private RuleEvaluationSource evaluationSource;

	@Column(name = "eval_target", nullable = false)
	private RuleEvaluationType evaluationType;

	@Column(name = "expression")
	private String expression;

	@JoinColumn(name = "source")
	private Account source;

	@JoinColumn(name = "target")
	private Account target;

	public TransactionResolverRule() {
	}

	public TransactionResolverRule(RuleEvaluationSource ruleSource, RuleEvaluationType ruleType, String expression, Account source, Account target) {
		this.evaluationSource = ruleSource;
		this.evaluationType = ruleType;
		this.expression = expression;
		this.source = source;
		this.target = target;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public RuleEvaluationSource getEvaluationSource() {
		return evaluationSource;
	}

	public void setEvaluationSource(RuleEvaluationSource evaluationSource) {
		this.evaluationSource = evaluationSource;
	}

	public RuleEvaluationType getEvaluationType() {
		return evaluationType;
	}

	public void setEvaluationType(RuleEvaluationType evaluationType) {
		this.evaluationType = evaluationType;
	}

	public Account getSource() {
		return source;
	}

	public void setSource(Account source) {
		this.source = source;
	}

	public Account getTarget() {
		return target;
	}

	public void setTarget(Account target) {
		this.target = target;
	}

	public String getExpression() {
		return expression;
	}

	public void setExpression(String expression) {
		this.expression = expression;
	}
}
